<template>
    <div class="Login">
        <div class="Login_box">
            <div class="Login_headImg">
                <img src="~static/images/login/bg_image_material_two.png" alt="">
            </div>
            <div class="Login_form">
                <div class="Login_form_group">
                    <input placeholder="请输入原密码" class="Login_form_input" v-model="pwd" name="pwd" maxlength="16" type="password" :class="{'Login_form_input_danger':errors.has('pwd')}" v-validate="'required|max:16|min:6'" />
                    <p class="Login_form_tip">
                        <span v-show="errors.has('pwd')">{{ errors.first('pwd') }}</span>
                    </p>
                </div>
                <div class="Login_form_group">
                    <input placeholder="请输入新密码" class="Login_form_input" v-model="newPwd" name="newPwd" maxlength="16" type="password" :class="{'Login_form_input_danger':errors.has('newPwd')}" v-validate="'required|max:16|min:6'" />
                    <p class="Login_form_tip">
                        <span v-show="errors.has('newPwd')">{{ errors.first('newPwd') }}</span>
                    </p>
                </div>
                <nuxt-link to="/login" class="Login_form_codeLogin fr">重置密码</nuxt-link>
                <div class="Login_form_footer">
                    <img src="~/static/images/login/button_normal.png" alt="" class="Login_form_submit" @click="doSubmit">
                    <nuxt-link to="/login" class="Login_form_forgetPwd">登录</nuxt-link>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
import { updatePassword } from '~/api/'
export default {
    data() {
        return {
            pwd: "",
            newPwd: ""
        }
    },
    methods: {
        /*doSubmit() {
            this.$validator.validateAll().then(async (result) => {
                if (!result) return
                const res = await updatePassword(this, this.pwd, this.newPwd)
                if (res.code === '0') {
                    this.$message.success('密码修改成功')
                    this.$router.push('/login/')
                } else {
                    this.$message.error(res.message)
                }
            })
        }*/
        doSubmit(){
            this.$validator.validateAll().then(async (result)=>{
                if(!result) return
                const res = await updatePassword (this, this.pwd,this.newPwd)
                if(res.code==='0'){
                    this.$message.success('修改成功')
                    this.$router.replace('/login/')
                }else{
                    this.$message.error(res.message)
                }
            })
        }
    }
}
</script>
